package com.micro.modual.service.impl;

import com.micro.common.MicroResponseCode;
import com.micro.core.exception.BizException;
import com.micro.core.frame.service.impl.AbstractBasicsServiceImpl;
import com.micro.core.resp.RespJson;
import com.micro.core.resp.RespJsonPageData;
import com.micro.modual.entity.Prefecture;
import com.micro.modual.extension.PrefectureExtension;
import com.micro.modual.mapper.PrefectureMapper;
import com.micro.modual.model.bo.prefecture.PrefectureBO;
import com.micro.modual.model.dto.prefecture.PrefectureListDTO;
import com.micro.modual.model.dto.prefecture.PrefectureStatusBO;
import com.micro.modual.service.PrefectureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;


/**
*  <h1>专区表  实现</h1>
 * @author LevelCoder
 * @version V1.0.0
 * @email LevelCoder@126.com
 * @date 2020-08-04 00:11:10
 */
@Service("prefectureService")
public class PrefectureServiceImpl extends AbstractBasicsServiceImpl<Prefecture,Long> implements PrefectureService {

    @Autowired
    private PrefectureMapper prefectureMapper;


    /**
     * <h2>新增专区表详情</h2>
     * @param prefectureBO {@link PrefectureBO} 专区表 新增/修改 请求对象
     * @return {@link RespJson} 返回结果基础类
     */
    @Override
    public RespJson addPrefecture(PrefectureBO prefectureBO) {
        Prefecture prefecture = PrefectureExtension.converAddPrefecture(prefectureBO);
        prefectureMapper.insertSelective(prefecture);
        return new RespJson(MicroResponseCode.SUCCESS.getResponseCode(), MicroResponseCode.SUCCESS.getResponseMessage());
    }

    /**
     * <h2>修改专区表详情</h2>
     * @param prefectureBO  {@link PrefectureBO} 专区表 新增/修改 请求对象
     * @return {@link RespJson} 返回结果基础类
     */
    @Override
    public RespJson editPrefecture(PrefectureBO prefectureBO) {
        Prefecture prefecture = PrefectureExtension.converEditPrefecture(prefectureBO);
        prefectureMapper.updateByPrimaryKeySelective(prefecture);
        return new RespJson(MicroResponseCode.SUCCESS.getResponseCode(),MicroResponseCode.SUCCESS.getResponseMessage());

    }

    /**
     * <h2>根据主键编号删除专区表信息</h2>
     * @param id  专区表 主键编号
     * @return  {@link RespJson} 返回结果基础类
     */

    @Override
    public RespJson deletePrefecture(Long id) {
        prefectureMapper.deleteByPrimaryKey(id);
        return new RespJson(MicroResponseCode.SUCCESS.getResponseCode(),MicroResponseCode.SUCCESS.getResponseMessage());
    }

    @Override
    public RespJson validataPrefectureNameExist(String prefectureName) {
        if(prefectureMapper.findPrefectureNameExist(prefectureName) > 0 ){
            throw new BizException(MicroResponseCode.PREFECTURE_HAS_EXIST.getResponseCode(),MicroResponseCode.PREFECTURE_HAS_EXIST.getResponseMessage());
        }else{
            return new RespJson(MicroResponseCode.SUCCESS.getResponseCode(),MicroResponseCode.SUCCESS.getResponseMessage());
        }
    }

    @Override
    public RespJson modifyPrefectureStatus(PrefectureStatusBO prefectureStatusBO) {
        Prefecture prefecture = prefectureMapper.selectByPrimaryKey(prefectureStatusBO.getPrefectureId());
        prefecture.setIsShow(prefectureStatusBO.getPrefectureStatus());
        prefectureMapper.updateByPrimaryKeySelective(prefecture);
        return new RespJson(MicroResponseCode.SUCCESS.getResponseCode(),MicroResponseCode.SUCCESS.getResponseMessage());
    }

}
